package com.scfinance.SPD.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.Properties;

public class PropsUtil {
    private static Logger _log = LoggerFactory.getLogger(PropsUtil.class);

    private static Properties properties = new Properties();

    public static Properties getProperties() {
        if (!properties.isEmpty()) {
            return properties;
        }
        try {
            InputStream in = PropsUtil.class.getClassLoader().getResourceAsStream("application.properties");
            properties.load(in);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            _log.error("读取file错误" + e);
        } catch (IOException e) {
            e.printStackTrace();
            _log.error("IO操作错误" + e);
        } catch (Throwable t) {
            _log.error("throwable", t);
        }
        return properties;
    }

    public static String getProperty(String key) {
        String property;

        try {
            getProperties();
            property = properties.getProperty(key);
        } catch (Exception e) {
            _log.debug("Property key not exit: " + key);
            return null;
        }

        return property;
    }

//    public static void main(String[] args) {
//        getProperties();
//        String str = properties.getProperty("project.ossPath");
//        System.out.println(str);
//    }

}
